package com.edu.compile.constant;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author yanzhao
 * @date 2021/10/23 13:20
 * @since 1.0.0
 */
public interface Comparator<T extends Comparator> {

    String getName();

    default boolean test(String name) {
        return this.getName().equals(name);
    }

    default boolean testOr(String name, T... ts) {
        boolean equals = this.getName().equals(name);

        if (equals) {
            return true;
        }
        if (!Optional.ofNullable(ts).isPresent()) {
            return false;
        }
        return Arrays.stream(ts).anyMatch(t -> t.getName().equals(name));
    }

    default boolean testAnd(String name, T... ts) {
        boolean equals = this.getName().equals(name);

        if (Optional.ofNullable(ts).isPresent()) {
            return equals && Arrays.stream(ts).allMatch(t -> t.getName().equals(name));
        }
        return equals;
    }
}
